# coding=utf-8
"""
作者：董新强 
创建时间：
描述：
"""
import functools

from framework.utilities import echo
from services.admin import is_admin
from services.service_base import ServiceBase


class AdminBase(ServiceBase):
    def __init__(self, usr):
        super().__init__(usr)

    @staticmethod
    def admin(error_value=None):
        def innertrycatch(function):
            @functools.wraps(function)
            def warp(*args, **kwargs):
                try:
                    if not is_admin(args[0].uid):
                        return error_value
                    return function(*args, **kwargs)
                except Exception as e:
                    echo(e)
                return error_value

            return warp

        return innertrycatch
